package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "车辆模块")
@Slf4j
@RestController
@RequestMapping("v1/vehicle/")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @Operation(summary = "查询车辆")
    @GetMapping("select")
    @ApiOperationSupport(order = 10)
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("开始处理【查询车辆】的请求，参数：{}", vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @Operation(summary = "保存车辆")
    @PostMapping("save")
    @ApiOperationSupport(order = 20)
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("开始处理【保存车辆】的请求，参数：{}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @Operation(summary = "删除车辆")
    @PostMapping("delete/{id}")
    @ApiOperationSupport(order = 30)
    public JsonResult deleteVehicle(@PathVariable Long id) {
        log.debug("开始处理【删除车辆】的请求，参数：{}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @Operation(summary = "解绑车辆")
    @PostMapping("unbind/{id}")
    @ApiOperationSupport(order = 40)
    public JsonResult unbindVehicle(@PathVariable Long id) {
        log.debug("开始处理【解绑车辆】的请求，参数：{}", id);
        vehicleService.unbindVehicle(id);
        return JsonResult.ok();
    }

    @Operation(summary = "绑定车辆")
    @PostMapping("bind/{geofenceId}/{id}")
    @ApiOperationSupport(order = 50)
    public JsonResult bindVehicle(@PathVariable Long geofenceId, @PathVariable Long id) {
        log.debug("开始处理【绑定车辆】的请求，参数：{}", geofenceId);
        vehicleService.bindVehicle(geofenceId, id);
        return JsonResult.ok();
    }


}





















